﻿using System.IO;
using GHIElectronics.NETMF.Hardware;
using InternetThermostat.DeviceAccessor;
using Microsoft.SPOT;

namespace InternetThermostat.Logging
{
    public static class Logger
    {
        public static void Log(string message)
        {

            var time = RealTimeClock.GetTime();

            // Write to output window
            Debug.Print(time + "\t" + message);


            var fileName = "Log - " + time.Year + "-" + time.Month + "-" + time.Day + ".log";
            var fileMode = File.Exists(Path.Combine(FileAccessor.Root, fileName)) ? FileMode.Append : FileMode.Create;

            //// Write to log file
            //using (Stream stream = FileAccessor.Open(fileName, fileMode))
            //{
            //    using (StreamWriter writer = new StreamWriter(stream))
            //    {
            //        writer.WriteLine("\n" + time + "\t" + message);

            //        writer.Close();
            //        writer.Dispose();
            //    }

            //    stream.Close();
            //    stream.Dispose();
            //}

        }

        public static void Log(object message)
        {
            Log(message.ToString());
        }
    }
}
